package main;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class WikiPage {
    private String name;
    private List<List<String>> words;
    /*
        List<List<String>> words: список списков строк из слов в тексте.
        List {
            0: List<String> words = {|Dog|}{| |}{|is|}{| |}...
            1: List<String> words = {|Dog|}{| |}{|is|}{| |}...
            ...
        }
     */
    private List<String> synonyms;

    public WikiPage(Text text) {
        name = text.getName();
        words = text.getWords();
        synonyms = text.getSynonyms();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<List<String>> getWords() {
        return words;
    }

    public void setWords(List<List<String>> words) {
        this.words = words;
    }

    public List<String> getSynonyms() {
        return synonyms;
    }

    public void setSynonyms(List<String> synonyms) {
        this.synonyms = synonyms;
    }

    public Boolean equals(WikiPage wikiPage) {
        return this.name.equals(wikiPage.getName()) ? true : false;
    }

    public void update(List<List<String>> newWords) {
        this.words = newWords;
    }

    public void createHtmlFile() throws IOException{
        PrintWriter printWriter = new PrintWriter(new FileWriter(new File("C:\\wiki\\html\\" + this.name + ".html")), true);
        String html = "<html><head><title>" + this.name + "</title></head><body><div class=\"text\"><p>";
        for(int i = 0; i < words.size(); i++) {
            List<String> line = words.get(i);
            String temp = "";
            for(String word: line) {
                temp += word;
            }
            html += temp;
            html += "<br>";
        }
        html += "</p></div></body></html>";
        printWriter.println(html);
    }
}
